package com.jb.web.form;

import com.jb.web.bean.Form;
import com.jb.web.context.WebContext;

import java.lang.reflect.Method;
import com.jb.faces.context.FacesContext;
import com.jb.framework.util.BeanUtil;
import com.jb.util.ClassUtil;


public class MethodForm extends Form {
    static {
        publish(MethodForm.class, DATA, "methodName");
        publish(MethodForm.class, DATA, "className");
        publish(MethodForm.class, DATA, "instance");
        publish(MethodForm.class, DATA, "result");
    }

    private Method method;
    private Object result;
    private String className;
    private String methodName;
    private boolean instance;

    public void setClassName(String className) {
        this.className = className;
    }

    public String getClassName() {
        return className;
    }

    public void setInstance(boolean instance) {
        this.instance = instance;
    }

    public boolean isInstance() {
        return instance;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public Object getResult() {
        return result;
    }

    public void processUpdates(FacesContext pCtx) {
        WebContext ctx = (WebContext) pCtx;

        if (isMyEvent(ctx)) {
            if (method == null) {
                Class clazz = ClassUtil.getClass(className);
                try {
                    method = clazz.getMethod(methodName, new Class[] { });
                } catch (Exception e) {
                    
                } 
            }
        }

        super.processUpdates(pCtx);
    }

    protected void generate(WebContext pCtx) {
        int count = 0;
    }
}
